<template>
  <img v-if="isTitle" src="@/assets/xinshuoImages/line.png" alt="" style="width: 100%" />
  <div ref="WorkReadyRef" class="box">
    <div class="seq">
      <div class="line1"></div>
      <div class="txt">作业前准备</div>
      <div class="line2"></div>
    </div>
    <div class="center">
      <div class="leftBox">
        <div class="Top" style="height: 50%">
          <Title title="需带工器具清单" img-url="toolList.png" style="margin-bottom: 14px"></Title>
          <div class="tools">
            <p v-for="item in toolArr.tool1" :key="item" class="one">
              {{ item }}
            </p>
          </div>
        </div>
        <!-- banner -->
        <div class="banner">
          <div class="bannerTop">
            <TitleAndLogo
              :show-two="true"
              title="工器具领用齐全合规"
              img-url1="AI.png"
              style="width: 226px; margin-right: 10px; font-size: 16px"
            />
            <TitleAndLogo
              :show-two="true"
              title="量具检验合规"
              img-url1="AI.png"
              style="width: 179px; font-size: 16px"
            />
          </div>
          <!-- banner -->
          <el-carousel :interval="5000" arrow="always" indicator-position="none">
            <el-carousel-item v-if="imgPeoples.banner1">
              <div class="images">
                <!-- 第一组 -->
                <div v-for="(item, index) in imgPeoples.banner1" :key="index" class="imgBox">
                  <img :src="urls.getAssetsFile(`${item.imgUrl}`)" alt="" />
                  <p class="name">{{ item.name }}</p>
                </div>
              </div>
            </el-carousel-item>
            <el-carousel-item v-if="imgPeoples.banner2">
              <div class="images">
                <!-- 第一组 -->
                <div v-for="(item, index) in imgPeoples.banner2" :key="index" class="imgBox">
                  <img :src="urls.getAssetsFile(`${item.imgUrl}`)" alt="" />
                  <p class="name">{{ item.name }}</p>
                </div>
              </div>
            </el-carousel-item>
            <el-carousel-item v-if="imgPeoples.banner3">
              <div class="images">
                <!-- 第一组 -->
                <div v-for="(item, index) in imgPeoples.banner3" :key="index" class="imgBox">
                  <img :src="urls.getAssetsFile(`${item.imgUrl}`)" alt="" />
                  <p class="name">{{ item.name }}</p>
                </div>
              </div>
            </el-carousel-item>
            <el-carousel-item v-if="imgPeoples.banner4">
              <div class="images">
                <!-- 第一组 -->
                <div v-for="(item, index) in imgPeoples.banner4" :key="index" class="imgBox">
                  <img :src="urls.getAssetsFile(`${item.imgUrl}`)" alt="" />
                  <p class="name">{{ item.name }}</p>
                </div>
              </div>
            </el-carousel-item>
          </el-carousel>
        </div>
      </div>

      <!-- table -->
      <div class="rightBox">
        <div class="Top" style="height: 50%">
          <Title title="需领用材料清单" img-url="menu.png" style="margin-bottom: 14px"></Title>
          <div class="tools">
            <p v-for="item in toolArr.tool2" :key="item" class="one">
              {{ item }}
            </p>
          </div>
        </div>
        <div class="tableBox">
          <TitleAndLogo title="耗材领用齐全合规" img-url1="AI.png" style="width: 226px" />
          <el-table
            ref="table"
            class="hd-table"
            :data="tableData"
            border
            style="width: 100%"
            :header-cell-style="{
              background: '#EEF5FF',
              textAlign: 'center',
              color: '#111',
            }"
          >
            <el-table-column prop="use" label="本次使用" />
            <el-table-column v-if="tableData[0].ganggui" prop="ganggui" label="钢轨" />
            <el-table-column v-if="tableData[0].jiaban" prop="jiaban" label="夹板" />
            <el-table-column v-if="tableData[0].luoshuan" prop="luoshuan" label="高强度螺栓" />
            <el-table-column v-if="tableData[0].dianpian" prop="dianpian" label="垫片" />
            <el-table-column v-if="tableData[0].jiaodian" prop="jiaodian" label="胶垫" />
            <el-table-column prop="cost" label="材料成本合计">
              <template #default>
                <p style="color: #1d6be1">{{ tableData[0].cost }}</p>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { nextTick, reactive, ref } from 'vue'
import urls from '@/utils/url'
let WorkReadyRef = ref()
let props = defineProps({
  isTitle: {
    type: Boolean,
    default: true,
  },
  toolArr: {
    type: Object,
    default: () => {},
  },
  imgPeoples: {
    type: Object,
    default: () => {},
  },
  tableData: {
    type: Array,
    default: () => [],
  },
})

const table = ref()
// 设置定时器
let timers
const scrollUp = (tableRef) => {
  const demo = tableRef.$refs.bodyWrapper.getElementsByClassName('el-scrollbar__wrap')[0]
  const tableScroll = ref(true)
  demo.addEventListener('mouseover', () => {
    tableScroll.value = false
  })
  demo.addEventListener('mouseout', () => {
    tableScroll.value = true
  })
  timers = setInterval(() => {
    if (tableScroll.value) {
      demo.scrollTop += 1
      if (demo.clientHeight + demo.scrollTop >= demo.scrollHeight) {
        demo.scrollTop = 0
      }
    }
  }, 60)
}
onMounted(() => {
  nextTick(() => {
    scrollUp(table.value)
  })
})

onBeforeUnmount(() => {
  clearInterval(timers) // 销毁定时器
})
defineExpose({
  WorkReadyRef,
})
</script>

<style lang="scss" scoped>
@import '@/styles/centerStyle.scss';
.box {
  display: flex;
  margin-top: 20px;
  // height: 600px;
  .seq {
    margin-right: 28px;
    height: 522px;
    margin-left: 6px;
    .txt {
      width: 90px;
    }
  }

  .center {
    display: flex;
    width: calc(100% - 118px);
    // 工具样式
    .tools {
      display: flex;
      flex-wrap: wrap;
      .one {
        width: 109px;
        height: 37px;
        line-height: 37px;
        background: rgba(29, 107, 225, 0.1);
        font-size: 18px;
        font-family:
          Source Han Sans CN-Medium,
          Source Han Sans CN;
        font-weight: 500;
        color: #1d6be1;
        margin-right: 3px;
        margin-bottom: 11px;
        text-align: center;
        &:nth-of-type(6n) {
          // margin-right: 0;
        }
      }
    }
    .leftBox {
      width: 50%;
      margin-right: 50px;
    }
    .rightBox {
      width: 50%;
    }
    // 轮播图
    .banner {
      width: 100%;
      // margin-top: 17px;
      height: 50%;
      .bannerTop {
        display: flex;
      }
      .title {
        display: flex;
      }
      :deep(.el-carousel__container) {
        height: 186px;
        margin-bottom: 16px;
      }
      //
      $imagesWidth: calc(675 / 723) * 100%;
      .images {
        display: flex;
        width: $imagesWidth;
        margin: auto;
        text-align: center;
        height: 100%;
        justify-content: space-between;
        .imgBox {
          background: #f5f9ff;
          box-shadow: 0px 2px 14px 0px rgba(0, 50, 135, 0.2);
          border-radius: 0px 0px 0px 0px;
          opacity: 1;
          border: 1px solid;
          border-image: linear-gradient(
              180deg,
              rgba(255, 255, 255, 1),
              rgba(179.40266132354736, 209.48730379343033, 255, 1)
            )
            1 1;
          &:first-child {
            margin-left: 12px;
          }
          &:last-child {
            margin-right: 12px;
          }
          > img {
            // margin: 0 4px;
            width: 94.6%;
            height: 141px;
          }
          .name {
            margin: 8px 0;
            text-align: center;
          }
        }
      }
      :deep(.el-carousel__arrow i) {
        width: 0;
        height: 0;
      }
      :deep(.el-carousel__arrow--left) {
        border-radius: 0;
        width: 25px;
        height: 44px;
        background: url('@/assets/xinshuoImages/leftArrow.png') no-repeat center/100% 100%;
        left: 2px !important;
      }
      :deep(.el-carousel__arrow--right) {
        border-radius: 0;
        width: 25px;
        height: 44px;
        background: url('@/assets/xinshuoImages/rightArrow.png') no-repeat center/100% 100%;
        right: 2px !important;
      }
    }
  }
}
// $tableBoxHeight: calc(90 / 511) * 100%;
.tableBox {
  width: 100%;
}
:deep(.el-table) {
  font-size: 16px !important;
}
.table-container {
  height: 400px;
  overflow-y: auto;
}
.hd-table {
  // height: 279px;
  text-align: center;
}
:deep(.el-table--enable-row-transition .el-table__body td.el-table__cell) {
  text-align: center;
}
:deep(.el-table__body .el-table__row) {
  height: 122px;
}
</style>
